import type { LayoutLoad } from './$types';
import { currentDataset$, type Dataset } from "@store/entity/dataset";
import { loadingByCode } from "@service/dataset"
import { get as getVal } from "svelte/store";
import { browser } from "$app/environment";
import type { DatasetEntry } from '@store/entity/dataset/entry';
import { getDatasetEntry } from "@service/dataset/entry"

export const load = (async ({params, url}) => {
   // if (!browser) {
  //   await loadingByCode(params.dataset_code);
  // }
  
  console.log('[entry_id]+layout =>', params)

  let entry: DatasetEntry
  if (browser) {
    entry = await getDatasetEntry(params.dataset_code, parseInt(params.entry_id))
  }
  
  return {
    entry,
    baseUrl: url.pathname.substring(0, url.pathname.indexOf(`/file`))
  };
}) satisfies LayoutLoad;
// this is needed to give us force prerendering of all pages